import {
  Toast
} from "vant";
import { scrollMixin } from "utils/mixin";
export default {
  components: {},
  props: {},
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      list: [],
      tabs: ['大区', '小区'],
      current: 0,
      teamYeji: 0, //团队业绩
      teamNum: 0, //团队人数
      teamNumA: 0, //A区团队人数
      teamNumB: 0, //B区团队人数
      aYeji: 0, //A区业绩
      bYeji: 0, //B区业绩
      //more
      isLoadMore: true,
      page: 1,
      total_page: 0,
    };
  },
  activated() {
    this.getData();
  },

  methods: {
    changeTab(index){ 
      this.current = index;
      this.page = 1;
      this.list = [];
      this.total_page = 0;
      this.getData();
    },
    getData() {
      var that = this;
      $http.post("ShengshiKeji.get_user_team", {
        uid: localStorage.getItem("uid") ? localStorage.getItem("uid") : localStorage.getItem("mid"),
        page: this.page
      }).then(res => {
        console.log(res, 'my_team');
        if (res.result == 1) {
             this.isLoadMore = true;
            // this.noneShow = false;
            this.total_page = that.current == 0 ? res.data.da_order_user.last_page : res.data.xiao_order_user.last_page;
            if (!this.total_page) {
              this.total_page = 0;
            }
          var obj = res.data;
          that.teamYeji = Number(obj.da_order_num) + Number(obj.xiao_order_num);
          that.teamNum = Number( obj.da_order_user.total) + Number(obj.xiao_order_user.total);
          that.aYeji = obj.da_order_num ? obj.da_order_num : 0;
          that.bYeji = obj.xiao_order_num ? obj.xiao_order_num : 0;
          that.list = that.current == 0 ? obj.da_order_user.data : obj.xiao_order_user.data;
          that.teamNumA = obj.da_order_user.total;
          that.teamNumB = obj.xiao_order_user.total;
        }else {
            this.isLoadMore = false; // 防止多次请求分页数据
            this.record_list = [];
        
        }


      });

    },
     //获取更多数据
    getMoreData() {
        console.log(this.page, 'page');
      if (!this.isLoadMore) return;
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page += 1;
        let json = {
            uid: window.localStorage.getItem("uid") ? window.localStorage.getItem("uid") : '',
            page: this.page
        };
        $http.post("ShengshiKeji.get_user_team", json, "加载中").then(response => {
          if (response.result === 1) {
            var nextPageData = this.current == 0 ? response.data.da_order_user.data : response.data.xiao_order_user.data;
            this.list = [...this.list,...nextPageData];
            this.isLoadMore = true;
          } else {
            this.page = this.page - 1;
            this.isLoadMore = false;
          }
        });
      }
    },
  }
};